﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Hands.Unit;
using Hands.Unit.DataBaseHelper;

namespace Hands.FileCache
{
    internal class MongoDBCache : Cache, ICache
    {
        private const string FILE_RESOURCE = "resource";

        IOperation mongoHelper = null;

        internal MongoDBCache()
        {
            mongoHelper = new MongoHelper(FILE_RESOURCE);
        }

        #region ICache 成员

        public File find(string fileName)
        {
            StringBuilder para = new StringBuilder();
            para.Append("{");
            para.Append("\"FileName\":\"");
            para.Append(fileName);
            para.Append("\"}");
            return mongoHelper.selectOne<File>(para.ToString());
        }

        #endregion

        protected override void addFileToCache(File file)
        {
            mongoHelper.insert<File>(file);
        }
    }
}
